Conditions | 1 |
Paths | 1 |
Total Lines | 97 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* eslint-enable describe it sinon */ |
||
8 | describe('the setTreeValue utility', () => { |
||
9 | |||
10 | it('Should turn a tree into a flat list with no identifier', () => { |
||
11 | |||
12 | const data = { |
||
13 | root: { |
||
14 | id: -1, |
||
15 | children: [ |
||
16 | { |
||
17 | id: 1, |
||
18 | parentId: -1, |
||
19 | children: [ |
||
20 | { |
||
21 | id: 11, |
||
22 | parentId: 1 |
||
23 | }, |
||
24 | { |
||
25 | id: 12, |
||
26 | parentId: 1, |
||
27 | children: [ |
||
28 | { |
||
29 | id: 121, |
||
30 | parentId: 12, |
||
31 | children: [ |
||
32 | { |
||
33 | id: 1211, |
||
34 | parentId: 121 |
||
35 | } |
||
36 | ] |
||
37 | } |
||
38 | ] |
||
39 | } |
||
40 | ] |
||
41 | }, |
||
42 | { |
||
43 | id: 2, |
||
44 | parentId: -1, |
||
45 | children: [ |
||
46 | { |
||
47 | id: 21, |
||
48 | parentId: 2 |
||
49 | } |
||
50 | ] |
||
51 | } |
||
52 | ] |
||
53 | } |
||
54 | }; |
||
55 | |||
56 | expect( |
||
57 | setTreeValue(data, [-1, 1, 12, 121], { _hideChildren: true }) |
||
58 | ).toEqual({ |
||
59 | root: { |
||
60 | id: -1, |
||
61 | children: [ |
||
62 | { |
||
63 | id: 1, |
||
64 | parentId: -1, |
||
65 | children: [ |
||
66 | { |
||
67 | id: 11, |
||
68 | parentId: 1 |
||
69 | }, |
||
70 | { |
||
71 | id: 12, |
||
72 | parentId: 1, |
||
73 | children: [ |
||
74 | { |
||
75 | id: 121, |
||
76 | _hideChildren: true, |
||
77 | parentId: 12, |
||
78 | children: [ |
||
79 | { |
||
80 | id: 1211, |
||
81 | parentId: 121 |
||
82 | } |
||
83 | ] |
||
84 | } |
||
85 | ] |
||
86 | } |
||
87 | ] |
||
88 | }, |
||
89 | { |
||
90 | id: 2, |
||
91 | parentId: -1, |
||
92 | children: [ |
||
93 | { |
||
94 | id: 21, |
||
95 | parentId: 2 |
||
96 | } |
||
97 | ] |
||
98 | } |
||
99 | ] |
||
100 | } |
||
101 | }); |
||
102 | }); |
||
103 | |||
104 | }); |
||
105 |